<template>
  <div class="area">
      <h4>参数设置</h4>
      <div class="container">
            <el-cascader
            :options="options2"
            @active-item-change="handleItemChange"
            :props="props"
            ></el-cascader>
      </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        options2: [
            {
              label:'12',
              value1:123456,
              cities:[]
            }
        ],
        props: {
            value: 'value1',
            children: 'cities'
        }
      };
    },
    mounted(){
       
        //   this.$api.get('/merchant/province',{}).then((res)=> {
        //       res  = res.data;
        //       console.log(res);
        //       this.options2 = res.data;
        //   })
      
    },
    methods: {
      handleItemChange(val) {
          console.log(val)
        if(val.length == 1) {
            console.log(val[0]);
             this.$api.get('/merchant/city',{
                    params:{
                        code_p:val[0]
                    }
            }).then((res)=> {
                 res = res.data;
                 let cityArr = res.data.map((v)=>{
                      console.log(v);
                        var obj = {};
                        obj.label = v.cityName;
                        obj.value = v.code_c;
                        obj.cities  = [];
                        return obj
                 });
                 console.log(cityArr.length);
                 if(cityArr.length>0) {
                    this.options2.forEach((v,i)=>{
                        if(v.value == val[0]) {
                        //  查询市 级接口
                                v.cities = cityArr;
                                console.log(v);
                            
                        }
                   })
                 }
               

                 
            })
           
        }else if(val.length ==2) {
            // 区 
            
            this.options2.forEach((v,i)=>{
                if(v.value == val[0]) {
                      v.cities.forEach((subV,i)=>{
                    //   市区 
                    if(subV.cities) {
                      subV.cities = [
                             {
                                 label:'najing',
                                 value:'9098'
                             }
                         ]   
                     }
                         
                  })
                }
            })
        } 
      },
    }
  };
</script>
<style  scoped>
</style>